 <template>
    <div class="l-right">
        <el-form :inline="true" :rules="rules" :model="npcTaskForm" class="demo-form-inline add-form" label-width="100px" ref="bidInfo">
            <el-form-item label="项名称：" prop="psTitle">
                <el-input v-model="npcTaskForm.psTitle"></el-input>
            </el-form-item>
            <el-form-item label="招标负责人：" label-width="120px" prop="leaderUserId" style="min-width:325px">
                <el-select v-model="npcTaskForm.leaderUserId" placeholder="请选择">
                    <el-option v-for="item in leaderUsers" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="品类：" prop="categoryName">
                <select-tree :multiple="false" ref="selectTree" v-model="npcTaskForm.categoryName"></select-tree>
              </el-form-item>
            <el-form-item label="采购组织：" prop="purOrgId">
                <el-select v-model="npcTaskForm.purOrgId" placeholder="请选择" @change="handleChange">
                    <el-option v-for="item in purOrgOptions" :key="item.id" :label="item.purOrgName" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="采购组：" prop="purGroupId">
                <el-select v-model="npcTaskForm.purGroupId" placeholder="请选择">
                    <el-option v-for="item in relationPurGroup" :key="item.id" :label="item.purGroupName" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="最小开标数量:" prop="minOpenNum" label-width="120px" style="min-width:325px">
                <el-input v-model="npcTaskForm.minOpenNum"></el-input>
            </el-form-item>
            <el-form-item label="框架招标：" label-width="120px">
                 <el-radio-group v-model="npcTaskForm.isFrame">
                    <el-radio label="1">是</el-radio>
                    <el-radio label="0">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="需保证金：" label-width="120px">
                 <el-radio-group v-model="npcTaskForm.isNeedBond">
                    <el-radio label="1">是</el-radio>
                    <el-radio label="0">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="需要开技术标：" label-width="120px">
                 <el-radio-group v-model="npcTaskForm.isNeedTecbidding">
                    <el-radio label="1">是</el-radio>
                    <el-radio label="0">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="招标说明：" prop="notice" class="w100">
                <UE v-model="npcTaskForm.notice" :config="config" ref="ue"></UE>
            </el-form-item>             
            <el-form-item label="投标截止日期：" label-width="135px" prop="tenderEtime" class="w50 llabel">
                <el-date-picker v-model="npcTaskForm.tenderEtimeStr" type="date" value-format="yyyy-MM-dd"
                    placeholder="投标截止日期" :picker-options="pickeroptions"
                    @change="()=>{npcTaskForm.openTimeStr='';}">
                </el-date-picker>
                <el-select v-model="npcTaskForm.tenderEtimeStr2" placeholder="请选择" style="width:49%">
                    <el-option v-for="item in 24" :key="item" :label="item+'时'" :value="item<10?`0${item}`:item"></el-option>
                </el-select>
            </el-form-item> 
            <el-form-item label="开标日期：" prop="openTimeStr" class="w50">
                <el-date-picker v-model="npcTaskForm.openTimeStr" type="date" value-format="yyyy-MM-dd"
                    placeholder="开标日期" :picker-options="pickeroptions1">
                </el-date-picker>
                <el-select v-model="npcTaskForm.openTimeStr2" placeholder="请选择" style="width:49%">
                    <el-option v-for="item in 24" :key="item" :label="item+'时'" :value="item<10?`0${item}`:item"></el-option>
                </el-select>
            </el-form-item> 
        </el-form>
    </div>
</template>
<script>
    import SelectTree from '@/components/common/select-ext/select-tree.vue';
    import UE from '@/components/common/ue/ue.vue';
    export default {
        data() {
            let _this=this;
            return {
                // 采购组织集合
                purOrgOptions:[],
                // 采购组集合
                relationPurGroup: [],
                // 工厂集合
                relationFactory: [],
                leaderUsers:[],
                rules:{
                    psTitle: [{required: true, message: '请输入项目名称', trigger: 'blur'}],
                    leaderUserId: [{required: true, message: '请选择招标负责人', trigger: 'change'}],
                    categoryId: [{required: true, message: '请选择品类', trigger: 'change'}],
                    purOrgId: [{required: true, message: '请选择采购组', trigger: 'change'}],
                    purGroupId: [{required: true, message: '请选择采购组', trigger: 'change'}],
                    minOpenNum: [{required: true, message: '请输入最小开标数量', trigger: 'blur'}],
                    tenderEtimeStr: [{required: true, message: '请选择投标截止日期', trigger: 'change'}],
                    openTimeStr: [{required: true, message: '请选择开标日期', trigger: 'change'}],   
                }, 
                formLabelWidth: '200px',
                fileList: [],
                // 定义附件的业务模块和业务动作
                fileData: {
                    busAction: "ADD",
                    tableId:'',
                    tableName: "BID"
                },
                defaultMsg: '',
                config: {
                    initialFrameWidth: 1450,
                    initialFrameHeight: 200,
                    enableAutoSave: false
                },
                pickeroptions:{
                    disabledDate(time) {
                        return time.getTime() <= Date.now()- 8.64e7
                    }
                },
                pickeroptions1:{
                    disabledDate(time) { 
                        return time.getTime() < (new Date(_this.npcTaskForm.tenderEtimeStr)).getTime()
                    }
                }
            };
        },
        props:['npcTaskForm'],
        // 监听品类下拉
        watch: {
        'npcTaskForm.categoryName':function(val){
            let data = this.$refs['selectTree'].getResultData();
            this.npcTaskForm.showvender=data.parentId||data.id||this.npcTaskForm.categoryId;
            this.npcTaskForm.categoryId = data.id||this.npcTaskForm.categoryId;
        }
        },
        components: {
            SelectTree,UE
        },
        mounted() {
            this.initData();
        },
        methods: {
            initData(){
                // 获取采购组织
                this.getSelectData('get', this.lib.config.host.masterData + '/system/purOrgMgt/purOrg/getPurOrgByUserId/' + this.getCurrUserId(), {}, 'id', 'purOrgName').then((data)=>{
                    this.purOrgOptions = data;
                });
                // 查询招标负责人
                this.axios.post(`${this.lib.config.host.system}/system/usermgt/users/findByRoleCode/BID_MANAGER`).then((res) => {
                    if(res.data){
                        this.leaderUsers = res.data;
                    }
                })
                .catch(function (error) {
                    console.log(error);
                });
            },
            // 采购组织在改变的时候查询采购组
            handleChange(value) {
                // 获取srm采购组
                this.getSelectData('post', this.lib.config.host.masterData + '/mdata/purOrgMgt/purGroup/getByPurOrgId/' + value, {}, 'id', 'purGroupName').then((data)=>{
                    this.relationPurGroup = data;
                });
                // 获取采购组织对应的工厂
                this.getSelectData('post', this.lib.config.host.masterData + '/system/factoryMgt/factorys/getFactoryByPurId/' + value, {}, 'id', 'factoryName').then((data)=>{
                    this.relationFactory = data;
                });
                // 把子组件的值发射至父组件
                this.$emit('changePurOrg', value);
            },
            // 工厂下拉改变时触发
            handleFactoryChange(value) {
                // 把子组件的值发射至父组件
                this.$emit('changeFactory', value);
            },   
            handleExceed(files, fileList){
                console.log(files);
                console.log(fileList);
            },
            // 自动上传附件后返回附件url和name
            uploadSuccess: function (response) {
                //附件上传成功回调
                this.npcTaskForm.attFileUrl = response.url;
                this.npcTaskForm.attFileName = response.fileName
            },
            getUEContentTxt() {
                let content = this.$refs.ue.getUEContentTxt(); // 调用子组件方法
                this.$notify({
                    message: content,
                    type: 'success'
                });
                console.log(content)
                return content;
            }
        }
  };
</script>
<style>
    .upload-file{
        display: flex;
        flex-direction: row-reverse;
        height: 40px;
    }
    .upload-file .el-upload-list {
        display: flex;
        flex-direction: row;
        width: calc(100% - 112px);
        border: 1px solid #dcdfe6;
        margin-right: 16px;
        border-radius: 4px;
    }
    .upload-file .el-upload-list li{
        margin-top: 0;
        line-height: 38px;
        vertical-align: middle;
    }
    .upload-file .el-upload-list li .el-icon-close{
        line-height: inherit;
        top:0;
    }
</style>